<?php 
    $name = 'tôi';
    $route = "";
    if(!$this->is_owner){
        $name = $this->owner_user->name;
        $route = "/".$this->owner_user->uid;
    }
    
    $nameLength = strlen($name);
    if($nameLength>16){
        $name = substr($name, 0, 15)."..";
    }
?>
            <div class="boxed category-user">
                <div class="boxTop border-radius-top">
                    <div class="boxName"><img src="<?php echo EVENT_STATIC_SERVER;?>/images/icons/icon_event_title.gif" alt="picture"/><span><h4>Sự kiện</h4></span></div>
                    <div class="tab float-right">
                        <div class="<?php echo $this->idx==1?"tabItemS":"tabItem";?>"><span><a href="<?php echo $this->idx==1?"#":"/event/my".$route;?>"><?php echo ucfirst($name);?> tham gia</a></span></div>   
                        <div class="<?php echo $this->idx==3?"tabItemS":"tabItem";?>"><span><a href="<?php echo $this->idx==3?"#":"/event/my/invited".$route;?>"><?php echo ucfirst($name);?> được mời</a></span></div>     
                        <div class="<?php echo $this->idx==2?"tabItemS":"tabItem";?>"><span><a href="<?php echo $this->idx==2?"#":"/event/my/own".$route;?>"><?php echo ucfirst($name);?> sáng lập</a></span></div>
                        <div class="<?php echo $this->idx==4?"tabItemS":"tabItem";?>"><span><a href="<?php echo $this->idx==4?"#":"/event/my/friend".$route;?>">Sự kiện của <?php echo ($this->is_owner?"bạn ":"bạn của ").$name;?></a></span></div>
                    </div>
                </div>
                <?php if($this->idx==4 && isset($this->friend_list)){
                    $currFriendName = "";
                    ?>
                <div class="boxBody" style="padding:5px 20px 10px;">
                    <form action="<?php echo $this->url;?>" method="get">
                    <table>
                        <tr>
                            <td>
                                Bạn của <?php echo $name;?>:
                                <select name="fid" class="select" onChange="changeFriend(this.value)">
                                    <option value="0"> Chọn một bạn </option>
                                    <?php 
                                        $totalFriend = count($this->friend_list);
                                        
                                        for($i=0; $i<$totalFriend; $i++){
                                            $fiend = $this->friend_list[$i];
                                            if($this->fid==$fiend->friendID)
                                                $currFriendName = $fiend->name;
                                            echo "<option value=\"".$fiend->friendID."\"".($this->fid==$fiend->friendID?" selected=\"selected\"":"").">".$fiend->name."</option>";
                                        }
                                    ?>
                                </select>
                        
                            </td>
                            <td>
                                &nbsp;
                                <input class="blogButton" type="submit" id="btnFriendView" title="Xem sự kiện của bạn" value=" Xem " style="display:none" />
                            </td>
                        </tr>
                    </table>
                    </form>
                    
                    <div class="clear"></div>
                    <hr />
                    <?php if($this->fid > 0){?>
                    <div style="margin-bottom:5px;">
                        <span style="display:block; float:left;">
                            Sự kiện của <a href="/home/<?php echo $currFriendName;?>" title="Xem trang nhà của <?php echo $currFriendName;?>"><strong class="colorOrange"><?php echo $currFriendName;?></strong></a>
                        </span>
                        <span style="display:block; float:right;">
                            Xem thêm sự kiện: <a href="/event/my/own/<?php echo $this->fid;?>"><strong class="colorOrange"><?php echo $currFriendName;?> sáng lập</strong></a> | <a href="/event/my/invited/<?php echo $this->fid;?>"><strong class="colorOrange"><?php echo $currFriendName;?> được mời</strong></a>
                        </span>
                    </div>
                    <?php }?>
                    <div class="clear"></div>
                </div>

                <script type="text/javascript">
                    var currFid = <?php echo (int)$this->fid;?>;
                    function changeFriend(fid){
                        if(!fid || fid==currFid){
                            $("#btnFriendView").hide();
                        }
                        else{
                            $("#btnFriendView").show();
                        }
                    }
                </script>
                <?php }?>
                <div class="boxBody border-radius-bottom"> 
                <?php if(isset($this->timeIndex) && $this->timeIndex != ""){?>
                <div class="filter">
                    <a href="<?php echo $this->url."s=all&".$this->ext_param;?>" class="<?php echo $this->timeIndex=="all"?" selected":"";?>">Tất cả</a> |
                    <a href="<?php echo $this->url."s=ongoing&".$this->ext_param;?>" class="<?php echo $this->timeIndex=="ongoing"?" selected":"";?>">Đang diễn ra</a> |
                    <a href="<?php echo $this->url."s=upcoming&".$this->ext_param;?>" class="<?php echo $this->timeIndex=="upcoming"?" selected":"";?>">Sắp bắt đầu</a> |
                    <a href="<?php echo $this->url."s=past&".$this->ext_param;?>" class="<?php echo $this->timeIndex=="past"?" selected":"";?>">Đã kết thúc</a>
                </div>
                <?php }?>
                <?php if(isset($this->status)){?>
                <div class="filter">
                    <a href="<?php echo $this->url?>" class="<?php echo $this->status==""?" selected":"";?>">Được mời</a> |
                    <a href="<?php echo $this->url."&s=maybe"?>" class="<?php echo $this->status=="maybe"?" selected":"";?>">Có thể tham dự</a>
                </div>
                <?php }?>
                                                    <?php echo $this->htmlEventList;?> 
                    <div class="clear"></div>

                </div>
            </div>
